home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / DynaLoader.Z / DynaLoader
Encoding:
Text File  |  1998-10-28  |  17.7 KB  |  529 lines

  1.  
  2.  
  3.  
  4.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       DynaLoader - Dynamically load    C libraries into Perl code
  10.  
  11.       _d_l__e_r_r_o_r(), _d_l__f_i_n_d_f_i_l_e(), _d_l__e_x_p_a_n_d_s_p_e_c(), _d_l__l_o_a_d__f_i_l_e(),
  12.       _d_l__f_i_n_d__s_y_m_b_o_l(), _d_l__f_i_n_d__s_y_m_b_o_l__a_n_y_w_h_e_r_e(),
  13.       _d_l__u_n_d_e_f__s_y_m_b_o_l_s(), _d_l__i_n_s_t_a_l_l__x_s_u_b(), _d_l__l_o_a_d__f_l_a_g_s(),
  14.       _b_o_o_t_s_t_r_a_p() -    routines used by DynaLoader modules
  15.  
  16.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  17.           package YourPackage;
  18.           require DynaLoader;
  19.           @ISA = qw(... DynaLoader ...);
  20.           bootstrap    YourPackage;
  21.  
  22.           #    optional method    for 'global' loading
  23.           sub dl_load_flags    { 0x01 }
  24.  
  25.  
  26.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  27.       This document    defines    a standard generic interface to    the
  28.       dynamic linking mechanisms available on many platforms.  Its
  29.       primary purpose is to    implement automatic dynamic loading of
  30.       Perl modules.
  31.  
  32.       This document    serves as both a specification for anyone
  33.       wishing to implement the DynaLoader for a new    platform and
  34.       as a guide for anyone    wishing    to use the DynaLoader directly
  35.       in an    application.
  36.  
  37.       The DynaLoader is designed to    be a very simple high-level
  38.       interface that is sufficiently general to cover the
  39.       requirements of SunOS, HP-UX,    NeXT, Linux, VMS and other
  40.       platforms.
  41.  
  42.       It is    also hoped that    the interface will cover the needs of
  43.       OS/2,    NT etc and also    allow pseudo-dynamic linking (using ld
  44.       -A at    runtime).
  45.  
  46.       It must be stressed that the DynaLoader, by itself, is
  47.       practically useless for accessing non-Perl libraries because
  48.       it provides almost no    Perl-to-C 'glue'.  There is, for
  49.       example, no mechanism    for calling a C    library    function or
  50.       supplying arguments.    A C::DynaLib module is available from
  51.       CPAN sites which performs that function for some common
  52.       system types.
  53.  
  54.       DynaLoader Interface Summary
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  71.  
  72.  
  73.  
  74.         @dl_library_path
  75.         @dl_resolve_using
  76.         @dl_require_symbols
  77.         $dl_debug
  78.         @dl_librefs
  79.         @dl_modules
  80.                                 Implemented    in:
  81.         bootstrap($modulename)                 Perl
  82.         @filepaths = dl_findfile(@names)             Perl
  83.         $flags = $modulename->dl_load_flags             Perl
  84.         $symref  = dl_find_symbol_anywhere($symbol)         Perl
  85.  
  86.         $libref  = dl_load_file($filename, $flags)         C
  87.         $symref  = dl_find_symbol($libref, $symbol)         C
  88.         @symbols = dl_undef_symbols()             C
  89.         dl_install_xsub($name, $symref [, $filename])     C
  90.         $message = dl_error                     C
  91.  
  92.  
  93.       @dl_library_path
  94.           The standard/default list    of directories in which
  95.           _d_l__f_i_n_d_f_i_l_e() will search    for libraries etc.
  96.           Directories are searched in order:  $dl_library_path[0],
  97.           [1], ... etc
  98.  
  99.           @dl_library_path is initialised to hold the list of
  100.           'normal' directories (/_u_s_r/_l_i_b, etc) determined by
  101.           CCCCoooonnnnffffiiiigggguuuurrrreeee    ($Config{'libpth'}).  This should ensure
  102.           portability across a wide    range of platforms.
  103.  
  104.           @dl_library_path should also be initialised with any
  105.           other directories    that can be determined from the
  106.           environment at runtime (such as LD_LIBRARY_PATH for
  107.           SunOS).
  108.  
  109.           After initialisation @dl_library_path can    be manipulated
  110.           by an application    using push and unshift before calling
  111.           _d_l__f_i_n_d_f_i_l_e().  Unshift can be used to add directories
  112.           to the front of the search order either to save search
  113.           time or to override libraries with the same name in the
  114.           'normal' directories.
  115.  
  116.           The load function    that _d_l__l_o_a_d__f_i_l_e() calls may require
  117.           an absolute pathname.  The _d_l__f_i_n_d_f_i_l_e() function    and
  118.           @dl_library_path can be used to search for and return
  119.           the absolute pathname for    the library/object that    you
  120.           wish to load.
  121.  
  122.       @dl_resolve_using
  123.           A    list of    additional libraries or    other shared objects
  124.           which can    be used    to resolve any undefined symbols that
  125.           might be generated by a later call to _l_o_a_d__f_i_l_e().
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  137.  
  138.  
  139.  
  140.           This is only required on some platforms which do not
  141.           handle dependent libraries automatically.     For example
  142.           the Socket Perl extension    library
  143.           (_a_u_t_o/_S_o_c_k_e_t/_S_o_c_k_e_t._s_o) contains references to many
  144.           socket functions which need to be    resolved when it's
  145.           loaded.  Most platforms will automatically know where to
  146.           find the 'dependent' library (e.g.,
  147.           /_u_s_r/_l_i_b/_l_i_b_s_o_c_k_e_t._s_o).  A few platforms need to be told
  148.           the location of the dependent library explicitly.     Use
  149.           @dl_resolve_using    for this.
  150.  
  151.           Example usage:
  152.  
  153.           @dl_resolve_using = dl_findfile('-lsocket');
  154.  
  155.  
  156.       @dl_require_symbols
  157.           A    list of    one or more symbol names that are in the
  158.           library/object file to be    dynamically loaded.  This is
  159.           only required on some platforms.
  160.  
  161.       @dl_librefs
  162.           An array of the handles returned by successful calls to
  163.           _d_l__l_o_a_d__f_i_l_e(), made by bootstrap, in the    order in which
  164.           they were    loaded.     Can be    used with _d_l__f_i_n_d__s_y_m_b_o_l() to
  165.           look for a symbol    in any of the loaded files.
  166.  
  167.       @dl_modules
  168.           An array of module (package) names that have been
  169.           bootstrap'ed.
  170.  
  171.       dl_error()
  172.           Syntax:
  173.  
  174.           $message = dl_error();
  175.  
  176.           Error message text from the last failed DynaLoader
  177.           function.     Note that, similar to errno in    unix, a
  178.           successful function call does not    reset this message.
  179.  
  180.           Implementations should detect the    error as soon as it
  181.           occurs in    any of the other functions and save the
  182.           corresponding message for    later retrieval.  This will
  183.           avoid problems on    some platforms (such as    SunOS) where
  184.           the error    message    is very    temporary (e.g., _d_l_e_r_r_o_r()).
  185.  
  186.       $dl_debug
  187.           Internal debugging messages are enabled when $dl_debug
  188.           is set true.  Currently setting $dl_debug    only affects
  189.           the Perl side of the DynaLoader.    These messages should
  190.           help an application developer to resolve any DynaLoader
  191.           usage problems.
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  203.  
  204.  
  205.  
  206.           $dl_debug    is set to $ENV{'PERL_DL_DEBUG'}    if defined.
  207.  
  208.           For the DynaLoader developer/porter there    is a similar
  209.           debugging    variable added to the C    code (see dlutils.c)
  210.           and enabled if Perl was built with the ----DDDDDDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG flag.
  211.           This can also be set via the PERL_DL_DEBUG environment
  212.           variable.     Set to    1 for minimal information or higher
  213.           for more.
  214.  
  215.       dl_findfile()
  216.           Syntax:
  217.  
  218.           @filepaths = dl_findfile(@names)
  219.  
  220.           Determine    the full paths (including file suffix) of one
  221.           or more loadable files given their generic names and
  222.           optionally one or    more directories.  Searches
  223.           directories in @dl_library_path by default and returns
  224.           an empty list if no files    were found.
  225.  
  226.           Names can    be specified in    a variety of platform
  227.           independent forms.  Any names in the form    ----llllnnnnaaaammmmeeee are
  228.           converted    into _l_i_b_n_a_m_e.*,    where .* is an appropriate
  229.           suffix for the platform.
  230.  
  231.           If a name    does not already have a    suitable prefix    and/or
  232.           suffix then the corresponding file will be searched for
  233.           by trying    combinations of    prefix and suffix appropriate
  234.           to the platform: "$name.o", "lib$name.*"    and "$name".
  235.  
  236.           If any directories are included in @names    they are
  237.           searched before @dl_library_path.     Directories may be
  238.           specified    as ----LLLLddddiiiirrrr.  Any other names are treated as
  239.           filenames    to be searched for.
  240.  
  241.           Using arguments of the form -Ldir    and -lname is
  242.           recommended.
  243.  
  244.           Example:
  245.  
  246.           @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
  247.  
  248.  
  249.       dl_expandspec()
  250.           Syntax:
  251.  
  252.           $filepath = dl_expandspec($spec)
  253.  
  254.           Some unusual systems, such as VMS, require special
  255.           filename handling    in order to deal with symbolic names
  256.           for files    (i.e., VMS's Logical Names).
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  269.  
  270.  
  271.  
  272.           To support these systems a _d_l__e_x_p_a_n_d_s_p_e_c() function can
  273.           be implemented either in the _d_l_*._x_s file    or code    can be
  274.           added to the autoloadable    _d_l__e_x_p_a_n_d_s_p_e_c()    function in
  275.           _D_y_n_a_L_o_a_d_e_r._p_m.  See _D_y_n_a_L_o_a_d_e_r._p_m    for more information.
  276.  
  277.       dl_load_file()
  278.           Syntax:
  279.  
  280.           $libref = dl_load_file($filename, $flags)
  281.  
  282.           Dynamically load $filename, which    must be    the path to a
  283.           shared object or library.     An opaque 'library reference'
  284.           is returned as a handle for the loaded object.  Returns
  285.           undef on error.
  286.  
  287.           The $flags argument to alters dl_load_file behaviour.
  288.           Assigned bits:
  289.  
  290.            0x01  make symbols available for    linking    later dl_load_file's.
  291.              (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
  292.              (ignored under VMS; this is a normal part of image    linking)
  293.  
  294.           (On systems that provide a handle    for the    loaded object
  295.           such as SunOS and    HPUX, $libref will be that handle.  On
  296.           other systems $libref will typically be $filename    or a
  297.           pointer to a buffer containing $filename.     The
  298.           application should not examine or    alter $libref in any
  299.           way.)
  300.  
  301.           This is the function that    does the real work.  It    should
  302.           use the current values of    @dl_require_symbols and
  303.           @dl_resolve_using    if required.
  304.  
  305.           SunOS: dlopen($filename)
  306.           HP-UX: shl_load($filename)
  307.           Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
  308.           NeXT:     rld_load($filename, @dl_resolve_using)
  309.           VMS:     lib$find_image_symbol($filename,$dl_require_symbols[0])
  310.  
  311.           (The _d_l_o_p_e_n() function is    also used by Solaris and some
  312.           versions of Linux, and is    a common choice    when providing
  313.           a    "wrapper" on other mechanisms as is done in the    OS/2
  314.           port.)
  315.  
  316.       dl_loadflags()
  317.           Syntax:
  318.  
  319.           $flags = dl_loadflags    $modulename;
  320.  
  321.           Designed to be a method call, and    to be overridden by a
  322.           derived class (i.e. a class which    has DynaLoader in its
  323.           @ISA).  The definition in    DynaLoader itself returns 0,
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 10/23/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  335.  
  336.  
  337.  
  338.           which produces standard behavior from _d_l__l_o_a_d__f_i_l_e().
  339.  
  340.       dl_find_symbol()
  341.           Syntax:
  342.  
  343.           $symref = dl_find_symbol($libref, $symbol)
  344.  
  345.           Return the address of the    symbol $symbol or undef    if not
  346.           found.  If the target system has separate    functions to
  347.           search for symbols of different types then
  348.           _d_l__f_i_n_d__s_y_m_b_o_l() should search for function symbols
  349.           first and    then other types.
  350.  
  351.           The exact    manner in which    the address is returned    in
  352.           $symref is not currently defined.     The only initial
  353.           requirement is that $symref can be passed    to, and
  354.           understood by, _d_l__i_n_s_t_a_l_l__x_s_u_b().
  355.  
  356.           SunOS: dlsym($libref,    $symbol)
  357.           HP-UX: shl_findsym($libref, $symbol)
  358.           Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
  359.           NeXT:     rld_lookup("_$symbol")
  360.           VMS:     lib$find_image_symbol($libref,$symbol)
  361.  
  362.  
  363.       dl_find_symbol_anywhere()
  364.           Syntax:
  365.  
  366.           $symref = dl_find_symbol_anywhere($symbol)
  367.  
  368.           Applies _d_l__f_i_n_d__s_y_m_b_o_l() to the members of @dl_librefs
  369.           and returns the first match found.
  370.  
  371.       dl_undef_symbols()
  372.           Example
  373.  
  374.           @symbols = dl_undef_symbols()
  375.  
  376.           Return a list of symbol names which remain undefined
  377.           after _l_o_a_d__f_i_l_e().  Returns () if    not known.  Don't
  378.           worry if your platform does not provide a    mechanism for
  379.           this.  Most do not need it and hence do not provide it,
  380.           they just    return an empty    list.
  381.  
  382.       dl_install_xsub()
  383.           Syntax:
  384.  
  385.           dl_install_xsub($perl_name, $symref [, $filename])
  386.  
  387.           Create a new Perl    external subroutine named $perl_name
  388.           using $symref as a pointer to the    function which
  389.           implements the routine.  This is simply a    direct call to
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 10/23/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  401.  
  402.  
  403.  
  404.           _n_e_w_X_S_U_B().  Returns a reference to the installed
  405.           function.
  406.  
  407.           The $filename parameter is used by Perl to identify the
  408.           source file for the function if required by _d_i_e(),
  409.           _c_a_l_l_e_r() or the debugger.     If $filename is not defined
  410.           then "DynaLoader"    will be    used.
  411.  
  412.       bootstrap()
  413.           Syntax:
  414.  
  415.           _b_o_o_t_s_t_r_a_p($module)
  416.  
  417.           This is the normal entry point for automatic dynamic
  418.           loading in Perl.
  419.  
  420.           It performs the following    actions:
  421.  
  422.       +o          locates an auto/$module directory    by searching
  423.               @INC
  424.  
  425.       +o          uses _d_l__f_i_n_d_f_i_l_e() to determine the filename to
  426.               load
  427.  
  428.       +o          sets @dl_require_symbols to ("boot_$module")
  429.  
  430.       +o          executes an _a_u_t_o/$_m_o_d_u_l_e/$_m_o_d_u_l_e._b_s file if it
  431.               exists (typically    used to    add to
  432.               @dl_resolve_using    any files which    are required
  433.               to load the module on the    current    platform)
  434.  
  435.       +o          calls _d_l__l_o_a_d__f_l_a_g_s() to determine how to    load
  436.               the file.
  437.  
  438.       +o          calls _d_l__l_o_a_d__f_i_l_e() to load the file
  439.  
  440.       +o          calls _d_l__u_n_d_e_f__s_y_m_b_o_l_s() and warns if any
  441.               symbols are undefined
  442.  
  443.       +o          calls _d_l__f_i_n_d__s_y_m_b_o_l() for "boot_$module"
  444.  
  445.       +o          calls _d_l__i_n_s_t_a_l_l__x_s_u_b() to install it as
  446.               "${module}::bootstrap"
  447.  
  448.       +o          calls &{"${module}::bootstrap"} to bootstrap the
  449.               module (actually it uses the function reference
  450.               returned by dl_install_xsub for speed)
  451.  
  452.      AAAAUUUUTTTTHHHHOOOORRRR
  453.       Tim Bunce, 11    August 1994.
  454.  
  455.       This interface is based on the work and comments of (in no
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 10/23/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))   22223333////OOOOcccctttt////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  467.  
  468.  
  469.  
  470.       particular order): Larry Wall, Robert    Sanders, Dean
  471.       Roehrich, Jeff Okamoto, Anno Siegel, Thomas Neumann, Paul
  472.       Marquess, Charles Bailey, myself and others.
  473.  
  474.       Larry    Wall designed the elegant inherited bootstrap
  475.       mechanism and    implemented the    first Perl 5 dynamic loader
  476.       using    it.
  477.  
  478.       Solaris global loading added by Nick Ing-Simmons with
  479.       design/coding    assistance from    Tim Bunce, January 1996.
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 10/23/98)
  526.  
  527.  
  528.  
  529.